﻿using Business.Base.DB.DBRules;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Business.Base.Utils
{
    public class BOFormater
    {
        public static String FormateObj(String action,object obj)
        {
            Type type = obj.GetType();
            StringBuilder sb = new StringBuilder();
            PropertyInfo[] properties = type.GetProperties();
            sb.Append("action:"+action+ " entity type: " + obj.GetType().Name + "\r");
            foreach (PropertyInfo propertyInfo in properties)
            {
                String valueString =" " ;
                DBFieldAttribute dbFieldAttribute = propertyInfo.GetCustomAttribute<DBFieldAttribute>();
                if (dbFieldAttribute != null)
                {
                    Object ret = propertyInfo.GetValue(obj);
                    sb.Append(" "+ propertyInfo.Name+"=" + ret.ToString()+"\r") ;                         
                }                
            }
            return sb.ToString();
        }
    }
}
